package com.bosssoft.user.permission.center.serve.controller;

import com.bosssoft.user.permission.center.serve.api.SubSystemApi;
import com.bosssoft.user.permission.center.serve.pojo.dto.Id;
import com.bosssoft.user.permission.center.serve.pojo.dto.SubSystemDTO;
import com.bosssoft.user.permission.center.serve.pojo.query.SubSystemQuery;
import com.bosssoft.user.permission.center.serve.pojo.vo.SubSystemVO;
import com.bosssoft.user.permission.center.serve.service.SubSystemService;
import common.data.commonresponse.CommonPage;
import common.data.commonresponse.CommonResponse;
import common.util.CommonResponseUtils;
import common.util.MyBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @className: SubSystemController
 * @description: 当前版本针对子系统管理的页面实现相应的功能接口,特别说明如下：
 * 1、接口注解做参数非空等检查
 * 2、控制层不处理异常，异常交给统一异常处理
 * 3、控制层的返回参数被统一包转为公共类型
 * @author: lanyukai
 * @date: 2024/6/11 13:44
 * @since 1.0
 **/
@RestController
public class SubSystemController implements SubSystemApi {
    @Autowired
    private SubSystemService subSystemService;

    @Override
    public CommonResponse<CommonPage<SubSystemVO>> selectSubSystemWithQuery(SubSystemQuery subSystemQuery) {
        return CommonResponseUtils.success(MyBeanUtil.copyProperties(subSystemService.selectSubSystemWithQuery(subSystemQuery), CommonPage<SubSystemVO>::new));
    }

    @Override
    public CommonResponse<SubSystemVO> selectSubSystemById(Long id) {
        return CommonResponseUtils.success(MyBeanUtil.copyProperties(subSystemService.selectSubSystemById(id), SubSystemVO::new));
    }

    @Override
    public CommonResponse<Boolean> addSubSystem(SubSystemVO subSystemVO) {
        return CommonResponseUtils.success(subSystemService.addSubSystem(MyBeanUtil.copyProperties(subSystemVO, SubSystemDTO::new)));
    }

    @Override
    public CommonResponse<Boolean> copySubSystem(@NotNull Id[] ids) {
        return CommonResponseUtils.success(subSystemService.copySubSystem(ids));
    }

    @Override
    public CommonResponse<Boolean> updateSubSystem(SubSystemVO subSystemVO) {
        return CommonResponseUtils.success(subSystemService.updateSubSystem(MyBeanUtil.copyProperties(subSystemVO, SubSystemDTO::new)));
    }

    @Override
    public CommonResponse<Boolean> deleteSubSystemById(Long id) {
        return CommonResponseUtils.success(subSystemService.deleteSubSystemById(id));
    }

    @Override
    public CommonResponse<Boolean> deleteSubSystemsByIds(Id[] ids) {
        return CommonResponseUtils.success(subSystemService.deleteSubSystemByIds(ids));
    }

    @Override
    public CommonResponse<Boolean> setSubSystemStatus(Long id) {
        return CommonResponseUtils.success(subSystemService.setSubSystemStatus(id));
    }

}
